﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityModel;
using Common;

namespace Services
{
    public class AdvertisingService
    {
        #region***属性数据***

        ShopDbEntities bdContext = DbContextHelper.GetCurrentDbContext();


        #endregion

        #region 获取所有广告位

        /// <summary>
        /// 获取所有广告位
        /// </summary>
        /// <returns></returns>
        ///  PagedList<Category>
        ///  
        public IQueryable<Advertising> GetAllList()
        {
            return bdContext.Advertisings.OrderByDescending(c => c.Id);
        }

        #endregion

        #region 新增数据

        public void Create(Advertising model)
        {
            bdContext.Advertisings.AddObject(model);
            bdContext.SaveChanges();
        }
        #endregion

        #region 更新内容
        /// <summary>
        /// 更新内容
        /// </summary>
        /// <param name="model"></param>
        public void Update(Advertising model)
        {
            Advertising ad = bdContext.Advertisings.FirstOrDefault(a => a.Id == model.Id);
            ad.Id = model.Id;
            ad.Contents = model.Contents;
            ad.Name = model.Name;
            ad.Names = model.Names;
            bdContext.SaveChanges();

        }
        #endregion

        #region 获取Model
        /// <summary>
        /// 获取Model
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Advertising GetModel(int id)
        {
            return bdContext.Advertisings.FirstOrDefault(a => a.Id == id);
        }
        #endregion

        #region 根据Names获取Model
        /// <summary>
        /// 根据Names获取Model
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Advertising GetModule(string names)
        {
            return bdContext.Advertisings.FirstOrDefault(a => a.Names == names);
        }
        #endregion
    }
}

